package pt.compflow.activity.workflow;

import pt.compflow.flowontology.model.Activity;
import pt.compflow.flowontology.model.FLOWO;
import pt.compflow.flowontology.model.FlowOntologyModel;
import pt.compflow.storage.SDBTripleStoreConnection;

/**
 *	This command runs an activity according to its type (Workflow, Task, Event or Gateway)
 *
 */
public class WorkflowControllerTimeoutActivityCommand implements Runnable {

	protected WorkflowController controller;
	protected String jobUri;
	protected String activityUri;
	
	public WorkflowControllerTimeoutActivityCommand(WorkflowController controller, String jobUri, String activityUri) {
		this.controller = controller;
		this.activityUri = activityUri;
		this.jobUri = jobUri;
	}

	@Override
	public void run() {
		
		SDBTripleStoreConnection store = new SDBTripleStoreConnection();
		store.openStore();
				
		FlowOntologyModel jobModel = store.connectNamedModel(jobUri);
		Activity act = jobModel.getActivityWithURI(activityUri);
		
		if(act.getPropertyResourceValue(FLOWO.hasState).getURI().compareTo(FLOWO.inProgress.getURI()) == 0) {
			controller.onActivityTimeout(jobUri, activityUri);
		}
		
		store.closeStore();
	}
	
}
